﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Multitouch.Framework.WPF;
using Multitouch.Framework.WPF.Input;
using Project_CFT2.Factory;
using Project_CFT2.Behavior;

namespace Project_CFT2.View
{
    /// <summary>
    /// Interaction logic for InteractiveFurnitureView.xaml
    /// </summary>
    public partial class InteractiveFurnitureView2 : UserControl
    {
        public Panel wpfpanel{get;set;}
        public InteractiveFurnitureView2()
        {

            MultitouchScreen.AddContactEnterHandler(this, ElementEnterHandler);

            InitializeComponent();
        }

        private static void ElementEnterHandler(object sender, ContactEventArgs e)
        {
            var element = sender as IInputElement;
            var furnitureElement = sender as InteractiveFurnitureView2;

            var touchPanel = furnitureElement.Parent as Multitouch.Framework.WPF.Controls.TouchablePanel;

            foreach (var item in touchPanel.Children)
            {
                if (item is InteractiveFurnitureView)
                {
                    var f = item as InteractiveFurnitureView;
                    f.HideButtons();
                }
                else if (item is InteractiveFurnitureView2)
                {
                    var f = item as InteractiveFurnitureView2;
                    f.HideButtons();
                }


            }
            furnitureElement.ShowButtons();

        }


        public void HideButtons()
        {
            btn_Info.Visibility = Visibility.Hidden;
            btn_Close.Visibility = Visibility.Hidden;
        }
        public void ShowButtons()
        {
            
            btn_Info.Visibility = Visibility.Visible;
            btn_Close.Visibility = Visibility.Visible;
        }

        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            var Room = this.Parent as Multitouch.Framework.WPF.Controls.TouchablePanel;
            Room.Children.Remove(this);
            
        }

        private void btn_Info_Click(object sender, RoutedEventArgs e)
        {
            //var Room = this.Parent as Multitouch.Framework.WPF.Controls.TouchablePanel;
            //var panel = Room.Parent as Multitouch.Framework.WPF.Controls.TouchablePanel;

            //var x = Room.Parent as IPanelViewFactory;
           

            ////var Room2 = this.Parent as ;
            //var y= Room.Parent as Panel;
            

            //IPanelViewFactory viewFactory = ElementDraggedCreateViewBehavior.GetPanelViewFactory((DependencyObject)Room);
            //int r = 3;
            foreach (var temp in wpfpanel.Children)
            {
                if (temp is FurniturePopupView2)
                {
                    var temp2 = temp as FurniturePopupView2;
                    temp2.DataContext = this.DataContext;
                    temp2.ShowPopup();
                }
            }
            
        }

    }
}
